<?php
namespace app\admin\controller;

use think\Controller;
use think\Request;
use think\Db;
use think\Session;
use think\captcha\Captcha;
class Login extends Controller
{
	public $template;
	public function _initialize()
    {
        
		$this->template='admin';
		$setting=Db::name('settinginfo')->where('id',Config()['wid'])->find();//网站配置加载
		$this->assign('setting',$setting);	
        $this->template='admin';
    }
	public function index()
	{
		$this->template='staff';
		return $this->fetch($this->template.'/login');
	}
	/*
	ver:1.0
	param:$userdata
	author:xy.zm
	date:2018/5/18
	*/
	public function login()
	{
		$captcha = new Captcha();
		$userinfo=Request::instance()->param();
		
		$userdata=Db::name('userinfo')->where('username',$userinfo['username'])->find();
		
		if(!(count($userdata)))
		{
			$this->error('用户不存在。');
		}
		else if(md5($userinfo['password'])!=$userdata['password'])
		{
			$this->error('密码不正确');
		}
		else if(!($captcha->check($userinfo['verify'])))
		{
			$this->error('验证码不正确');
		}
		session('userdata',$userdata);
		
		return redirect('__ROOT__/admin/index/menu');
	}
    
}